import Recommender.RecommenderTagBased as RecommenderTagBased
import datetime
import random
import pandas as pd
import Core.IO as IO

from Core.Config import *
config = Config()
database = config.DataBase()
realtime = config.RealTime(db=1)


def Test_Recommender_Performance():
    #
    users = []
    h = realtime.GetHashObjects("User_Tags_Batch1")
    for user, tags in h.items():
        if user not in users:
            users.append(user)

    #
    randNum = 100
    randUsers = []
    for i in range(randNum):
        randomIndex = random.randint(0, len(users) - 1)
        randUsers.append(users[randomIndex])

    datetime1 = datetime.datetime.now()
    for userPin in randUsers:
        df = RecommenderTagBased.Recommander_SimpleTag(database, realtime, userPin, debug=False)
        a = 0
    k = 0
    datetime2 = datetime.datetime.now()
    print("Total time:  " + str((datetime2 - datetime1).total_seconds() / randNum))




# ---Cache Tags---
RecommenderTagBased.Cache_Article_Tags_Batch(database, realtime, "Corpus4_LDA_90")
RecommenderTagBased.Cache_Tag_Articles_Batch(database, realtime, "Corpus4_LDA_90")

# ---User Action map to User Tag---
# RecommenderTagBased.Add_Tag_on_User_Batch(database, realtime)


# Check_MissingUsers_WhoReadArticles()

# ---Run Recommender---
RecommenderTagBased.Recommander_SimpleTag(database, realtime, "jd_74d22170a3e7e")


# ---Test Performance---
Test_Recommender_Performance()